﻿using AdminBase.Interface;
using AdminBase.Model.Entitys;
using SqlSugar;

namespace AdminBase.Service
{
    /// <summary>
    /// 文件服务类
    /// </summary>
    public class FilesService : IFilesService
    {
        private ISqlSugarClient _db { get; set; }

        public FilesService(ISqlSugarClient db)
        {
            _db = db;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public bool Add(Files entity)
        {
            return _db.Insertable(entity).ExecuteCommand() > 0;
        }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="fileID">文件Guid</param>
        /// <returns></returns>
        public Files Get(string fileID)
        {
            return _db.Queryable<Files>().First(p => p.FileID == fileID);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="fileID"></param>
        /// <returns></returns>
        public bool Delete(string fileID)
        {
            return _db.Deleteable<Files>().Where(f => f.FileID == fileID).ExecuteCommand() > 0;
        }
    }
}
